package com.heba.greenmulu.user;

import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;

import com.heba.AppManager;
import com.heba.Cfg;
import com.heba.config.CommonConfig;
import com.heba.dialog.CustomDialogView;
import com.heba.greenmulu.BaseActivity;
import com.heba.greenmulu.GuideActivity;
import com.heba.greenmulu.MainActivity;
import com.heba.greenmulu.R;
import com.heba.greenmulu.WebviewActivity;
import com.heba.helper.MemberShipHelper;

/**
 * 设置页面
 * <p>
 * Created by jason on 2019/2/12.
 */

public class UserSettingActivity extends BaseActivity implements View.OnClickListener {

    private LinearLayout linear_language;
    private LinearLayout linear_notification;
    private LinearLayout linear_about;
    private LinearLayout linear_privacy;
    private LinearLayout linear_terms;
    private LinearLayout linear_logout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_setting);
        initTopbar();
        findViewById();
        initView();
    }

    @Override
    protected void findViewById() {
        linear_language = findViewById(R.id.linear_language);
        linear_notification = findViewById(R.id.linear_notification);
        linear_about = findViewById(R.id.linear_about);
        linear_privacy = findViewById(R.id.linear_privacy);
        linear_terms = findViewById(R.id.linear_terms);
        linear_logout = findViewById(R.id.linear_logout);

        linear_language.setOnClickListener(this);
        linear_notification.setOnClickListener(this);
        linear_about.setOnClickListener(this);
        linear_privacy.setOnClickListener(this);
        linear_terms.setOnClickListener(this);
        linear_logout.setOnClickListener(this);
    }

    @Override
    protected void initView() {
        txt_title.setText(getResources().getString(R.string.settings));
    }

    @Override
    public void onClick(View v) {
        Bundle bundle = new Bundle();
        switch (v.getId()) {
            case R.id.linear_language:
                openActivity(UserLanguageActivity.class);
                break;
            case R.id.linear_notification:
                openActivity(UserNotificationActivity.class);
                break;
            case R.id.linear_about:
                openActivity(UserAboutActivity.class);
                break;
            case R.id.linear_privacy:
                bundle.putString(CommonConfig.WEBVIEW_TITLE, getResources().getString(R.string.privacy_policy));
                bundle.putString(CommonConfig.WEBVIEW_URL, Cfg.PrivacyUrl);
                openActivity(WebviewActivity.class, bundle);
                break;
            case R.id.linear_terms:
                bundle.putString(CommonConfig.WEBVIEW_TITLE, getResources().getString(R.string.term_of_use));
                bundle.putString(CommonConfig.WEBVIEW_URL, Cfg.TermsUseUrl);
                openActivity(WebviewActivity.class, bundle);
                break;
            case R.id.linear_logout:
                //登出
                new CustomDialogView(new CustomDialogView.OnCustomDialogClickListener() {
                    @Override
                    public void onYesClick() {
                        MemberShipHelper.logOut();
                        openActivity(MainActivity.class);
                        AppManager.getAppManager().finishAllActivity();
                    }

                    @Override
                    public void onNoClick() {

                    }
                }).showDialog(UserSettingActivity.this, getResources().getString(R.string.confirm_logout), "");
                break;
            default:
                break;
        }
    }
}
